package com.tanhua.dubbo.api.mongo;

import com.tanhua.domain.mongo.TestPaper;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;

import java.util.List;

@Service
public class TestPaperApiImpl implements TestPaperApi {

    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public void save(TestPaper paper) {
        mongoTemplate.save(paper);
    }

    @Override
    public List<TestPaper> findAll() {
        Query query = new Query();
        return mongoTemplate.find(query,TestPaper.class);
    }

    @Override
    public void updateStatus(Integer isLock,Integer type) {
        Query query = new Query(Criteria.where("type").is(type));
        Update update = new Update();
        update.set("isLock", isLock);
        mongoTemplate.updateFirst(query, update, TestPaper.class);
    }
}
